#include "MouseHandler.h"

namespace GeorgeLib
{

MouseHandler::MouseHandler(void)
{
	for(int i = 0; i < 5; ++i)
	{
		MouseButtons[i] = false;
	}
	DiffX = 0;
	DiffY = 0;
	LastX = 800 >> 1;
	LastY = 400 >> 1;
}

MouseHandler::~MouseHandler(void)
{
}

void MouseHandler::HandleMouseFunc(int button, int state, int x, int y)
{
	switch(button)
	{
	case GLUT_LEFT_BUTTON:
		if		(state == GLUT_DOWN)	MouseButtons[LEFT] = true;
		else if	(state == GLUT_UP)		MouseButtons[LEFT] = false;
		break;
	case GLUT_RIGHT_BUTTON:
		if		(state == GLUT_DOWN)	MouseButtons[RIGHT] = true; 
		else if	(state == GLUT_UP)		MouseButtons[RIGHT] = false;
		break;
	case GLUT_MIDDLE_BUTTON:
		if		(state == GLUT_DOWN)	MouseButtons[RIGHT] = true; 
		else if	(state == GLUT_UP)		MouseButtons[RIGHT] = false;
		break;
	case 3:
		if		(state == GLUT_DOWN)	MouseButtons[WHEEL_UP] = true; 
		else if	(state == GLUT_UP)		MouseButtons[WHEEL_UP] = false;
		break;
	case 4:
		if		(state == GLUT_DOWN)	MouseButtons[WHEEL_DOWN] = true; 
		else if	(state == GLUT_UP)		MouseButtons[WHEEL_DOWN] = false;
		break;
	default:
		break;
	}

	DiffX = x - LastX;
	DiffY = y - LastY;
	LastX = x;
	LastY = y;
}

void MouseHandler::HandleMotionFunc(int x, int y)
{
	DiffX = x - LastX;
	DiffY = y - LastY;
	LastX = x;
	LastY = y;
}

} // namespace GeorgeLib